<template>
  <div class="submission-list-body">
    <el-table
        :data="submissionList">
      <el-table-column
          align="center"
          label="用户ID">
        <template slot-scope="scope">
          <el-link type="info" @click="goUserInfo(scope.row.userId)">
            {{ scope.row.userId }}
          </el-link>

        </template>
      </el-table-column>
      <el-table-column
          align="center"
          label="题目ID">
        <template slot-scope="scope">
          <el-link type="info" @click="goProblemDetail(scope.row.problemId, scope.row.contestId)">
            {{ scope.row.problemId }}
          </el-link>

        </template>
      </el-table-column>
      <el-table-column
          align="center"
          @click="goSubmissionDetail"
          label="运行ID">
        <template slot-scope="scope">
          <el-link type="info" @click="goSubmissionDetail(scope.row.runId)">
            {{ scope.row.runId }}
          </el-link>

        </template>
      </el-table-column>
      <el-table-column
          align="center"
          label="Status">
        <template slot-scope="scope">
          <el-tag :type="STATUS_COLOR_HASH[scope.row.result]" effect="dark" size="mini">
            {{ STATUS_HASH[scope.row.result] }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column
          prop="score"
          align="center"
          label="提交得分">
      </el-table-column>
      <el-table-column
          align="center"
          label="Language">
        <template slot-scope="scope">
          <span>{{LANGUAGE_HASH[scope.row.language]}}</span>
        </template>
      </el-table-column>
      <el-table-column
          prop="length"
          align="center"
          label="代码长度">
      </el-table-column>
      <el-table-column
          prop="memoryused"
          align="center"
          label="使用内存">
      </el-table-column>

      <el-table-column
          prop="timeused"
          align="center"
          label="最长用时">
      </el-table-column>
      <el-table-column
          prop="submitTime"
          align="center"
          label="提交时间">
      </el-table-column>
      <el-table-column v-if="isAdminRole()">
        <template slot-scope="scope">
          <el-button @click="reJudge(scope.row.runId)">重测</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {reJudge} from "@/network/submission";
import {mapGetters} from "vuex";
import {JUDGE_OPTIONS} from "@/utils/constants";

export default {
  name: "SubmissionListBody",
  props: {
    submissionList: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  data() {
    return {
      STATUS_HASH: JUDGE_OPTIONS.STATUS_HASH,
      STATUS_COLOR_HASH: JUDGE_OPTIONS.STATUS_COLOR_HASH,
      LANGUAGE_HASH: JUDGE_OPTIONS.LANGUAGE_HASH,
    }
  },
  methods: {
    ...mapGetters(
        [
          'isAdminRole'
        ]
    ),
    goUserInfo(userId) {
      this.$router.push({
        path: '/user/profile',
        query: {
          userId: userId
        }
      })
    },
    goProblemDetail(problemId, contestId) {
      if (contestId !== null && contestId !== -1) {
        this.$router.push(
            {
              path: '/contests/' + contestId + '/problems/' + problemId
            }
        )

      } else {
        this.$router.push(
            {
              path: '/problem/' + problemId
            }
        )
      }

    },
    goSubmissionDetail(runId) {
      this.$router.push(
          {
            path: '/submission/' + runId
          }
      )
    },
    reJudge(submissionId) {
      reJudge(null, null, null, submissionId)
          .then(res => {
            this.$message.success("成功提交评测")
            console.log(res);
          })
    }
  }
}
</script>

<style scoped>

</style>